import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '../views/Layout'
import Login from '../views/Login'
import Category from '../views/Category'
import Home from '../views/Home'
import Good from '../views/Good'
import Cart from '../views/cart'
import Settlement from '@/views/settlement'
import Pay from '@/views/Pay'
import PayResult from '@/views/PayResult'

const routes = [
  {
    path: '/login',
    component: Login
  },
  {
    path: '/',
    component: Layout,
    children: [{
      path: '', // 如果二级路由path为空将作为默认渲染的路由
      component: Home
    },
    {
      // 加name跟path后面写id呼应，没id 页面是不显示的
      name: 'category',
      path: 'category/:id',
      component: Category
    },
    {
      path: 'good/:id',
      component: Good
    },
    {
      path: 'cart',
      component: Cart
    },
    {
      path: 'settlement',
      component: Settlement
    },
    {
      path: 'pay',
      component: Pay
    },
    {
      path: 'pay/callback',
      component: PayResult
    }
    ]
  }
]

const router = createRouter({
  // 使用hash方式实现路由
  history: createWebHashHistory(),
  routes
})

export default router
